package com.gtxc.kotlinmvvm.utlis;

import android.annotation.SuppressLint;
import android.os.Build;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

//显示Webwvie H5共用
public class WebH5Utlis {
    @SuppressLint("SetJavaScriptEnabled")
    public static void H5Web(WebView webView, String h5url){
        WebSettings mWebSettings = webView.getSettings();
        //支持javascript
        mWebSettings.setJavaScriptEnabled(true);
        // 设置可以支持缩放
        mWebSettings.setSupportZoom(true);
        // 设置出现缩放工具
        mWebSettings.setBuiltInZoomControls(true);
        //扩大比例的缩放
        mWebSettings.setUseWideViewPort(true);
        webView.setWebViewClient(new WebViewClient());
        //自适应屏幕
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
        } else {
            mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        }
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
        webView.loadUrl(h5url);

    }
    //重载onKeyDown的函数，使其在页面内回退,而不是直接退出程序




}
